package com.ruoyi.product.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.product.mapper.TbBrandMapper;
import com.ruoyi.product.domain.TbBrand;
import com.ruoyi.product.service.ITbBrandService;

/**
 * 商品品牌Service业务层处理
 * 
 * @author Keven
 * @date 2025-08-04
 */
@Service
public class TbBrandServiceImpl implements ITbBrandService 
{
    @Autowired
    private TbBrandMapper tbBrandMapper;

    /**
     * 查询商品品牌
     * 
     * @param brandId 商品品牌主键
     * @return 商品品牌
     */
    @Override
    public TbBrand selectTbBrandByBrandId(Integer brandId)
    {
        return tbBrandMapper.selectTbBrandByBrandId(brandId);
    }

    /**
     * 查询商品品牌列表
     * 
     * @param tbBrand 商品品牌
     * @return 商品品牌
     */
    @Override
    public List<TbBrand> selectTbBrandList(TbBrand tbBrand)
    {
        return tbBrandMapper.selectTbBrandList(tbBrand);
    }

    /**
     * 新增商品品牌
     * 
     * @param tbBrand 商品品牌
     * @return 结果
     */
    @Override
    public int insertTbBrand(TbBrand tbBrand)
    {
        tbBrand.setCreateTime(DateUtils.getNowDate());
        return tbBrandMapper.insertTbBrand(tbBrand);
    }

    /**
     * 修改商品品牌
     * 
     * @param tbBrand 商品品牌
     * @return 结果
     */
    @Override
    public int updateTbBrand(TbBrand tbBrand)
    {
        tbBrand.setUpdateTime(DateUtils.getNowDate());
        return tbBrandMapper.updateTbBrand(tbBrand);
    }

    /**
     * 批量删除商品品牌
     * 
     * @param brandIds 需要删除的商品品牌主键
     * @return 结果
     */
    @Override
    public int deleteTbBrandByBrandIds(Integer[] brandIds)
    {
        return tbBrandMapper.deleteTbBrandByBrandIds(brandIds);
    }

    /**
     * 删除商品品牌信息
     * 
     * @param brandId 商品品牌主键
     * @return 结果
     */
    @Override
    public int deleteTbBrandByBrandId(Integer brandId)
    {
        return tbBrandMapper.deleteTbBrandByBrandId(brandId);
    }

    @Override
    public TableDataInfo getBrandList(TbBrand tbBrand,Integer pageNum,Integer pageSize) {
        //构建分页
        Page<TbBrand> page = new Page<>(pageNum, pageSize);
        //查询
        Page<TbBrand> brandPage = tbBrandMapper.selectPage(page, null);
        TableDataInfo repDate = new TableDataInfo();
        //赋值
        repDate.setCode(HttpStatus.SUCCESS);
        repDate.setRows(brandPage.getRecords());
        repDate.setMsg("查询成功");
        repDate.setTotal(brandPage.getTotal());
        //返回
        return repDate;
    }
}
